package com.gok.seasonmovie.controller;

import com.gok.seasonmovie.entity.Cinema;
import com.gok.seasonmovie.entity.Comment;
import com.gok.seasonmovie.entity.Movie;
import com.gok.seasonmovie.service.CinemaService;
import com.gok.seasonmovie.service.CommentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class CinemaController {

    @Resource
    private CinemaService cinemaService;

    @PostMapping("/cinemas")
    public Map<String, Object> getCinemas(@RequestParam("longitude") String longitude,@RequestParam("latitude") String latitude) {
        try{
            Map<String, Object> response = new HashMap<>();
            response.put("code", 200);
            response.put("msg", "ok");
            List<Cinema> cinemas= cinemaService.getAllCinema(longitude,latitude);
            response.put("data", cinemas);
            return response;
        }catch (RuntimeException e) {
            Map<String, Object> errorResponse = new HashMap<>();
            errorResponse.put("code", 600);
            errorResponse.put("msg", "Database error: " + e.getMessage());
            return errorResponse;
        }
    }

    @PostMapping("/getCinemaByCid")
    public Map<String, Object> getCinemaByCid(@RequestParam String id){
        try{
            Map<String, Object> response = new HashMap<>();
            response.put("code", 200);
            response.put("msg", "ok");
            List<Cinema> cinemas= cinemaService.getCinemaByCid(id);
            response.put("data", cinemas);
            return response;
        }catch (RuntimeException e) {
            Map<String, Object> errorResponse = new HashMap<>();
            errorResponse.put("code", 600);
            errorResponse.put("msg", "Database error: " + e.getMessage());
            return errorResponse;
        }

    }

    @PostMapping("/getCinemaByMid")
    public Map<String, Object> getCinemaByMid(@RequestParam String id,@RequestParam("longitude") String longitude,@RequestParam("latitude") String latitude){
        try{
            Map<String, Object> response = new HashMap<>();
            response.put("code", 200);
            response.put("msg", "ok");
            List<Cinema> cinemas= cinemaService.getCinemaByMid(id,longitude,latitude);
            response.put("data", cinemas);
            return response;
        }catch (RuntimeException e) {
            Map<String, Object> errorResponse = new HashMap<>();
            errorResponse.put("code", 600);
            errorResponse.put("msg", "Database error: " + e.getMessage());
            return errorResponse;
        }
    }




}